package demo.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import demo.util.SwingUtil;

public class ManagerFrame extends JFrame implements ActionListener {
	private JMenu reader;
	private JMenuItem showReader,addReader,updateReader,selectReader,delectReader;
	private JMenu book;
	private JMenuItem addBook,updateBook,selectBook,delectBook;
	private JMenu lend;
	private JMenuItem lendBook,returnBook;
	private JMenu manager;
	private JMenuItem updateperson,updatePassword;
	private JPanel centerPanel = new JPanel();
	private JLabel lblStatus;
	
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ManagerFrame frame = new ManagerFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}*/
	
	public ManagerFrame() {
		setTitle("教务管理系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 780, 620);
		
		//将窗体居中
		SwingUtil.setWindowCenter(this);
		JPanel contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JMenuBar menuBar = new JMenuBar();
		contentPane.add(menuBar, BorderLayout.NORTH);
		
		reader = new JMenu("读者管理");
		menuBar.add(reader);
		reader.setFont(new Font("",Font.BOLD,20));
		reader.setForeground(Color.blue);
		
		//showReader,addReader,updateReader,selectReader,delectReader
		
		showReader = new JMenuItem("读者列表");
		showReader.setFont(new Font("",Font.BOLD,18));
		showReader.setForeground(Color.blue);
		showReader.addActionListener(this);
		reader.add(showReader);
		reader.addSeparator();
		
		addReader = new JMenuItem("添加读者");
		addReader.setFont(new Font("",Font.BOLD,18));
		addReader.setForeground(Color.blue);
		addReader.addActionListener(this);
		reader.add(addReader);
		reader.addSeparator();
		
		updateReader = new JMenuItem("编辑读者");
		updateReader.setFont(new Font("",Font.BOLD,18));
		updateReader.setForeground(Color.blue);
		updateReader.addActionListener(this);
		reader.add(updateReader);
		reader.addSeparator();
		
		selectReader = new JMenuItem("查询读者");
		selectReader.setFont(new Font("",Font.BOLD,18));
		selectReader.setForeground(Color.blue);
		selectReader.addActionListener(this);
		reader.add(selectReader);
		reader.addSeparator();
		
		delectReader = new JMenuItem("删除读者");
		delectReader.setFont(new Font("",Font.BOLD,18));
		delectReader.setForeground(Color.blue);
		delectReader.addActionListener(this);
		reader.add(delectReader);
		
		
		book = new JMenu("图书管理");
		menuBar.add(book);
		book.setFont(new Font("",Font.BOLD,20));
		book.setForeground(Color.blue);
		
		//addBook,updateBook,selectBook,delectBook
		addBook = new JMenuItem("添加图书");
		addBook.setFont(new Font("",Font.BOLD,18));
		addBook.setForeground(Color.blue);
		addBook.addActionListener(this);
		book.add(addBook);
		book.addSeparator();
		
		updateBook = new JMenuItem("编辑图书");
		updateBook.setFont(new Font("",Font.BOLD,18));
		updateBook.setForeground(Color.blue);
		updateBook.addActionListener(this);
		book.add(updateBook);
		book.addSeparator();
		
		selectBook = new JMenuItem("图书查询");
		selectBook.setFont(new Font("",Font.BOLD,18));
		selectBook.setForeground(Color.blue);
		selectBook.addActionListener(this);
		book.add(selectBook);
		book.addSeparator();
		
		delectBook = new JMenuItem("删除图书");
		delectBook.setFont(new Font("",Font.BOLD,18));
		delectBook.setForeground(Color.blue);
		delectBook.addActionListener(this);
		book.add(delectBook);
		
		
		lend=new JMenu("借阅管理");
		menuBar.add(lend);
		lend.setFont(new Font("",Font.BOLD,20));
		lend.setForeground(Color.blue);
		
		//lendBook,returnBook
		lendBook = new JMenuItem("借书管理");
		lendBook.setFont(new Font("",Font.BOLD,18));
		lendBook.setForeground(Color.blue);
		lendBook.addActionListener(this);
		lend.add(lendBook);
		lend.addSeparator();
		
		returnBook = new JMenuItem("还书管理");
		returnBook.setFont(new Font("",Font.BOLD,18));
		returnBook.setForeground(Color.blue);
		returnBook.addActionListener(this);
		lend.add(returnBook);
		
		
		manager = new JMenu("个人信息");
		menuBar.add(manager);
		manager.setFont(new Font("",Font.BOLD,20));
		manager.setForeground(Color.blue);
		
		//updateperson,updatePassword
		updateperson = new JMenuItem("修改个人信息");
		updateperson.setFont(new Font("",Font.BOLD,18));
		updateperson.setForeground(Color.blue);
		updateperson.addActionListener(this);
		manager.add(updateperson);
		manager.addSeparator();
		
		updatePassword = new JMenuItem("修改密码");
		updatePassword.setFont(new Font("",Font.BOLD,18));
		updatePassword.setForeground(Color.blue);
		updatePassword.addActionListener(this);
		manager.add(updatePassword);

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO 自动生成的方法存根
		if (e.getSource() == showReader) {// 如果事件源是“读者列表”菜单项
			//在原窗体中显示读者记录			
			this.remove(centerPanel);// 删除窗体中心区域的组件
			centerPanel = new ReaderShow();// 要添加到中心区域的新组件
			this.add(centerPanel, BorderLayout.CENTER);// 将新组件添加到中心区域
			this.validate();

		}else if (e.getSource() == addReader) {// 如果事件源是“添加读者”菜单项
			//创建一个新的窗体来显示读者记录
			JDialog insertDialog = new JDialog();
			insertDialog.setSize(300, 360);
			insertDialog.getContentPane().add(new ReaderAdd(), BorderLayout.CENTER);
			insertDialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			//将窗体居中
			SwingUtil.setWindowCenter(insertDialog);
			//insertDialog.pack();
			insertDialog.setModal(true);
			insertDialog.setVisible(true);
			
	    }else if (e.getSource() == updateReader) {// 如果事件源是“编辑读者”菜单项			
			//创建一个新的窗体来显示读者记录
			JFrame updateFrame = new JFrame();
			updateFrame.setTitle("修改读者信息");
			updateFrame.setSize(400, 400);
			updateFrame.getContentPane().add(new ReaderUpdate(), BorderLayout.CENTER);
			updateFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			//将窗体居中
			SwingUtil.setWindowCenter(updateFrame);
			updateFrame.setVisible(true);
				
		}else if(e.getSource() == selectReader) {
			JFrame selectFrame = new JFrame();
			selectFrame.setTitle("查找读者");
			selectFrame.setSize(780, 400);
			selectFrame.getContentPane().add(new ReaderSelect(), BorderLayout.CENTER);
			selectFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			//将窗体居中
			SwingUtil.setWindowCenter(selectFrame);
			selectFrame.setVisible(true);
		}
		
		
	}

}
